// packageI/newDistributor/index/index.js
const app = getApp();
Page({
    data: {
        language: '',
        statusType: 0,
        statusTabs: [
            {name: 0, title: "全部"},
            {name: 1, title: "已结算"},
            {name: 2, title: "未结算"},
            {name: 5, title: "预计佣金"},
            {name: 3, title: "已冻结"},
            {name: 4, title: "已失效"}
        ],

        page: 1,
        loading: false,
        finished: false,
  
        statisticsInfo: null,
        list: [],
    },
    onLoad: function () {
        let language = wx.getStorageSync('langIndex');
        this.setData({ 'language': language.en});
    },
    
    onShow: function () {
        this.getData();
    },

    getData () {
        wx.showLoading({title: 'Loading'});
        let urlStr = app.getNetAddresss("plugin.fk-distribution.frontend.controllers.center.index");
        app._getNetWork({
            url: urlStr,
            data: {
                page: this.data.page,
                record_status: this.data.statusType
            },
            success: (response) => {
                let res = response.data;
                let {result, msg, data} = res;
                let recordData = data.list;
                if (result != 1) {  
                    app.tips(msg);
                    return false;
                }
                if (this.data.page == 1) {
                    this.setData({ statisticsInfo: data.info });
                }
                if (this.data.page >= recordData.last_page || recordData.data.length < recordData.per_page) {
                    this.setData({finished: true});
                }
                this.setData({
                    list: this.data.page > 1 ? this.data.list.concat(recordData.data) : recordData.data,
                    page: ++this.data.page
                })
            },

            complete () {
                wx.hideLoading();
            }
        });
    },

    changeStatus (event) {
        this.setData({statusType: event.detail.name});
        this.initGetData();
        this.getData();
    },

    initGetData () {
        this.setData({
            page: 1,
            finished: false,
            loading: false,
        })
      },

    onReachBottom () {
        if (this.data.finished) {
            return false;
          }
        this.getData();
    },
})